/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package btreetestat;

import java.util.HashMap;

/**
 *
 * @author Yarolye
 */
public class TreeNode {

   private TreeContainer children; 
   private TreeContainer treeContainer;
   private TreeContainer biggerChildren;
   private Integer Value;
   private boolean lastNode=false;

    public TreeContainer getChildren() {
        return children;
    }

    public TreeContainer getBiggerChildren() {
        return biggerChildren;
    }

    public void setBiggerChildren(TreeContainer biggerChildren) {
        this.biggerChildren = biggerChildren;
    }

    public void setChildren(TreeContainer children) {
        this.children = children;
    }


    public Integer getValue() {
        return Value;
    }

    public void setValue(Integer Value) {
        this.Value = Value;
    }

    public TreeContainer getTreeContainer() {
        return treeContainer;
    }

    public void setTreeContainer(TreeContainer treeContainer) {
        this.treeContainer = treeContainer;
    }

    public boolean isLastNode() {
        return lastNode;
    }

    public void setLastNode(boolean lastNode) {
        this.lastNode = lastNode;
    }
   
    public TreeNode getSmallerChild(){
        TreeNode treeNode= getChildren().lastEntry().getValue();
        TreeContainer childContainer= treeNode.getChildren();
        while( childContainer!=null){
            treeNode=childContainer.lastEntry().getValue();
            childContainer= treeNode.getBiggerChildren();
        }
        return treeNode;
    }
    
    public TreeNode getBiggerChild(){
        TreeContainer startContainer;
        TreeNode biggerChild=null;
        if(this.isLastNode()){
            startContainer=biggerChildren;
        }else{
            startContainer=this.getTreeContainer().higherEntry(Value).getValue().getChildren();
        }
        while(startContainer!=null){
            biggerChild=startContainer.firstEntry().getValue();
            startContainer=biggerChild.getChildren();
        }
        return biggerChild;
    }
   
}
